<meta charset="utf-8" />
<div class="breadcrumbs" id="breadcrumbs">
	<ul class="breadcrumb">
		<li><i class="ace-icon fa fa-home home-icon"></i> <a href="index">系统管理</a>
		</li>

		<li><span>权限管理</span></li>
	</ul>
	<!-- /.breadcrumb -->
</div>
<div class="page-content">
	<div class="row">
		<div class="col-xs-12">
			<div class="clearfix"></div>
			<div class="table-header">权限管理</div>

			<div>
				<div id="dynamic-table_wrapper"
					class="dataTables_wrapper form-inline no-footer">
					<div class="row">
						<div class="widget">
							<div class="widget-main">
								<form class="form-inline" id="selefrom" action="privilege/sele"
									method="post">
									权限名称<input type="search" style="width:120px;height:30px " ; class="form-control input-sm"
										placeholder="输入查询内容" aria-controls="dynamic-table" name="qxmc" id="selectqxmc"> 
									权限编号<input type="search" style="width:120px;height:30px " ; class="form-control input-sm"
										placeholder="输入查询内容" aria-controls="dynamic-table" name="qxbh" id="selectqxbh">
										<!-- <select name="seletype"
										aria-controls="dynamic-table" class="form-control ">
										<option value="privilege_name">权限名称</option>
										<option value="privilege_id">权限编号</option>
									</select> -->
									<button id="selectfromsb" class="btn btn-info btn-sm" style="height:30px " ;>查询</button>
									<button id="selectfromcz" class="btn btn-info btn-sm" style="height:30px " ;>重置</button>
								</form>
							</div>
						</div>
					</div>
					<table
						class="table table-striped table-bordered table-hover dataTable no-footer DTTT_selectable"
						id="dynamic-table" role="grid"
						aria-describedby="dynamic-table_info">
						<thead>
							<tr role="row">

								<th>权限编号</th>
								<th><i class="icon-time bigger-110 hidden-480"></i>权限名称</th>
								<th class="hidden-480">上层目录</th>
								<th>状态</th>
								<!-- <th>操作</th> -->
							</tr>
						</thead>
						<tbody id="privipage">
						</tbody>
					</table>
					<div class="row">
						<div class="col-xs-12 col-md-12">
							<div class=" pull-left">
								<label>显示<select name="dynamic-table_length"
									aria-controls="dynamic-table" class="form-control input-sm" id="sel"><option
											value="10">10</option>
										<option value="20">20</option>
										<option value="50">50</option>
										<option value="100">100</option>
								</select> 条记录</label>
							</div>
							<div class="dataTables_paginate paging_simple_numbers">
										<ul class="pagination" id="get_pagination3">
										</ul>
										<div class="laypage_main laypageskin_molv" id="laypage_3">
											<span class="laypage_curr" style="background-color:#2283C5">1</span><span
												class="laypage_total"><label>到第</label><input max="1"
												min="1" class="laypage_skip" type="number"><label>页</label>
												<button type="button" class="laypage_btn">
													确定
													</button>
											</span>
										</div>
									</div>

									
							<!-- <div class="dataTables_paginate paging_simple_numbers "
								id="dynamic-table_paginate">
								<ul id="package" class="pagination">
								</ul>
							</div> -->
						</div>
					</div>
				</div>

			</div>
		</div>
	</div>
</div>
</div>

<!-- 更改每页显示数据的数目 -->
<script type="text/javascript">
var sel=document.getElementById("sel");
sel.onchange=function(){
/* alert(sel.options[sel.selectedIndex].value); */
		$.post("privilege/gghs", {"pagen" :sel.options[sel.selectedIndex].value}, function(data) {
			pagedemo(1);							
		});}
</script>

<script type="text/javascript">
	function pageO(data){
			if(data.totalPage!=1){
				$("#laypage_3").addClass("hide");
				$("#get_pagination3").removeClass("hide");
				laypage({
				cont : $('#get_pagination3'), //容器。值支持id名、原生dom对象，jquery对象,
				pages : data.totalPage, //总页数
				skip : true, //是否开启跳页
				skin : '#2283C5',//保持ace中间的样式
				first: 1,
				last : data.totalPage, //总页数，将尾页显示为总页数
				curr : data.pageNumber,//当前页
				groups : 5, //连续显示分页数
				jump : function(obj, first) {
					if (!first) { //一定要加此判断，否则初始时会无限刷新
						pagedemo(obj.curr);
					}
					}
				});
			}else{
				$("#get_pagination3").addClass("hide");
				$("#laypage_3").removeClass("hide");
			}
			
			
	}


	pagedemo(1);
	function pagedemo(n) {
		$.get("privilege/pagedemo", {
			"pageNumber" : n
		}, function(data) {
			packlist(data);
			pageO(data[0].list);
		});
	}

	function pack(data) { //填充数据
		var dataStr = "";
		$.each(data, function(i, v) {
			dataStr += packlist(v);
		});
		$("#privipage").html(dataStr);
	}

	function packlist(data) {
		var dataStr = "";
		$.each(data, function(i, d) {
		$.each(d.list.list, function(i, v) {
		dataStr += '<tr>';
		dataStr += '<td>' + v.privilege_id + '</td>';
		dataStr += '<td>' + v.privilege_name + '</td><td>';
		if(v.parent_id==0){dataStr += '无';}
		$.each(d.privileges, function(i, p) {
			if(p.privilege_id==v.parent_id) dataStr += p.privilege_name;
			
		});
		dataStr += '</td><td>';
		if (v.status == true) {
			dataStr += '<span class="label label-sm label-success">';
			dataStr += '启用';
			dataStr += '</span>';
		} else {
			dataStr += '<span class="label label-sm label-inverse arrowed-in">停用</span>';
		}
		dataStr += '</td>';
		dataStr += '</tr>';
		});});
		$("#privipage").html(dataStr);
		
	};
	
	/* 撤销查询 */
		$("#selectfromcz").click(function() {
		document.getElementById("selectqxmc").value="";
		document.getElementById("selectqxbh").value="";
		$.post("privilege/sele", $("#selefrom").serialize(), function(data) {
			pagedemo(1);
		})
		return false;
	});

	/* 查询 */
	$("#selectfromsb").click(function() {
		$.post("privilege/sele", $("#selefrom").serialize(), function(data) {
		/* $.each(data, function(i, d) {
			if(d.list.list==""){
				errorMsg('满足该条件的数据不存在！');
				document.getElementById("selectqxmc").value="";
				document.getElementById("selectqxbh").value="";
				return false;
			}else{
				packlist(data);
				packpage(data[0].list);
				return false;
			}
			}); */
			pagedemo(1);
		})
		return false;
	});

	function addForm() {
		document.getElementById("pform").reset();
		$('#add').removeClass("hide");
		userModel = layer.open({
			type : 1,
			shade : [ 0.5 ],
			title : '修改订单', //不显示标题
			area : [ '40%', '500px' ], //显示空间
			content : $('#add'), //捕获的元素
			btn : [ '提交', '取消' ],
			yes : function(index, layero) { //或者使用btn1
				$.post("add", $("#pform").serialize(), function(data) {

					layer.close(index);
					$('#add').addClass("hide");
					document.getElementById("pform").submit();
				});
			},
			cancel : function(index) {
				layer.close(index);
				$('#add').addClass("hide"); //取消继续隐藏
			},
		});
	};
	
	
		//错误提示(传入错误信息)
	function errorMsg(errorInfo) {
		layer.confirm(errorInfo, {
			btn : [ '确定' ]
		//按钮
		}, function(index) {
			layer.close(index);
		});
	}
</script>
